{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f65fa9ce",
   "metadata": {},
   "source": [
    "# OHLC Plot with Interactive Range Tool\n",
    "\n",
    "An OHLC (Open–High–Low–Close) plot displaying stock price movements for Apple Inc. This example uses HoloViews to add a range slider that helps exploring long time series."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fe4fff36",
   "metadata": {},
   "outputs": [],
   "source": [
    "import hvplot.pandas  # noqa\n",
    "import pandas as pd\n",
    "from holoviews.plotting.links import RangeToolLink\n",
    "\n",
    "df = hvplot.sampledata.apple_stocks(\"pandas\").set_index(\"date\").loc[\"2020-01-01\":]\n",
    "\n",
    "# Main OHLC plot\n",
    "ohlc_plot = df.hvplot.ohlc(\n",
    "    ylabel='Price ($)',\n",
    "    grid=True,\n",
    "    width=700,\n",
    "    height=300,\n",
    ")\n",
    "# Overview OHLC plot for interactive range selection\n",
    "overview = df.hvplot.ohlc(\n",
    "    width=700,\n",
    "    height=100,\n",
    "    ylabel='',\n",
    "    xaxis=None,\n",
    "    yaxis=None,\n",
    "    hover=False,\n",
    "    ylim=(0, 100),\n",
    ")\n",
    "# Link the range between overview and main plot\n",
    "RangeToolLink(\n",
    "    overview,\n",
    "    ohlc_plot,\n",
    "    boundsx=(pd.Timestamp(\"2023-01-01\"), pd.Timestamp(\"2023-06-30\")),\n",
    ")\n",
    "\n",
    "# Stack the plots vertically\n",
    "(ohlc_plot + overview).cols(1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "55231095-759d-4527-af26-f4666129dd89",
   "metadata": {},
   "source": [
    ":::{seealso}\n",
    "- [OHLC Plots reference documentation](../../ref/api/manual/hvplot.hvPlot.ohlc.ipynb).\n",
    ":::"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
